home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / chrome / toolkit.jar / content / global / printPreviewBindings.xml < prev    next >
Encoding:
Extensible Markup Language  |  2005-10-04  |  14.4 KB  |  405 lines

  1. <?xml version="1.0"?>
  2.  
  3.  
  4. <!DOCTYPE window [
  5. <!ENTITY % printPreviewDTD SYSTEM "chrome://global/locale/printPreview.dtd" >
  6. %printPreviewDTD;
  7. <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
  8. %globalDTD;
  9. ]>
  10.  
  11. <bindings id="printPreviewBindings"
  12.    xmlns="http://www.mozilla.org/xbl"
  13.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  14.  
  15.   <binding id="printpreviewtoolbar" 
  16.            extends="chrome://global/content/bindings/toolbar.xml#toolbar">
  17.     <resources>
  18.       <stylesheet src="chrome://global/skin/printPreview.css"/>
  19.     </resources>
  20.  
  21.     <content>
  22.       <xul:button label="&print.label;" accesskey="&print.accesskey;"
  23.         oncommand="PrintUtils.print();" icon="print"/>
  24.  
  25.       <xul:button label="&pageSetup.label;" accesskey="&pageSetup.accesskey;"
  26.         oncommand="this.parentNode.doPageSetup();"/>
  27.  
  28.       <xul:vbox align="center" pack="center">
  29.         <xul:label value="&page.label;" accesskey="&page.accesskey;" control="pageNumber"/>
  30.       </xul:vbox>
  31.       <xul:toolbarbutton class="home-arrow tabbable" chromedir="&locale.dir;"
  32.         oncommand="parentNode.navigate(0, 0, 'home');" tooltiptext="&homearrow.tooltip;"/>
  33.       <xul:toolbarbutton class="left-arrow tabbable" chromedir="&locale.dir;"
  34.         oncommand="parentNode.navigate(-1, 0, 0);" tooltiptext="&leftarrow.tooltip;"/>
  35.       <xul:hbox align="center" pack="center">
  36.         <xul:textbox id="pageNumber" size="3" value="1" lastvalid="1"
  37.           onchange="navigate(0, this.value, 0);"/>
  38.         <xul:label value="&of.label;"/>
  39.         <xul:label value="1"/>
  40.       </xul:hbox>
  41.       <xul:toolbarbutton class="right-arrow tabbable" chromedir="&locale.dir;"
  42.         oncommand="parentNode.navigate(1, 0, 0);" tooltiptext="&rightarrow.tooltip;"/>
  43.       <xul:toolbarbutton class="end-arrow tabbable" chromedir="&locale.dir;"
  44.         oncommand="parentNode.navigate(0, 0, 'end');" tooltiptext="&endarrow.tooltip;"/>
  45.  
  46.       <xul:toolbarseparator class="toolbarseparator-primary"/>
  47.       <xul:vbox align="center" pack="center">
  48.         <xul:label value="&scale.label;" accesskey="&scale.accesskey;" control="scale"/>
  49.       </xul:vbox>
  50.  
  51.       <xul:hbox align="center" pack="center">
  52.         <xul:menulist id="scale" crop="none" 
  53.           oncommand="parentNode.parentNode.scale(this.selectedItem.value);">
  54.           <xul:menupopup>
  55.             <xul:menuitem value="0.3" label="&p30.label;"/>
  56.             <xul:menuitem value="0.4" label="&p40.label;"/>
  57.             <xul:menuitem value="0.5" label="&p50.label;"/>
  58.             <xul:menuitem value="0.6" label="&p60.label;"/>
  59.             <xul:menuitem value="0.7" label="&p70.label;"/>
  60.             <xul:menuitem value="0.8" label="&p80.label;"/>
  61.             <xul:menuitem value="0.9" label="&p90.label;"/>
  62.             <xul:menuitem value="1" label="&p100.label;"/>
  63.             <xul:menuitem value="1.25" label="&p125.label;"/>
  64.             <xul:menuitem value="1.5" label="&p150.label;"/>
  65.             <xul:menuitem value="1.75" label="&p175.label;"/>
  66.             <xul:menuitem value="2" label="&p200.label;"/>
  67.             <xul:menuseparator/>
  68.             <xul:menuitem flex="1" value="ShrinkToFit" 
  69.               label="&ShrinkToFit.label;"/>
  70.             <xul:menuitem value="Custom" label="&Custom.label;"/>
  71.           </xul:menupopup>
  72.         </xul:menulist>
  73.       </xul:hbox>
  74.  
  75.       <xul:toolbarseparator class="toolbarseparator-primary"/>
  76.       <xul:hbox align="center" pack="center">
  77.         <xul:toolbarbutton label="&portrait.label;" checked="true"
  78.           accesskey="&portrait.accesskey;"
  79.           type="radio" group="orient" class="toolbar-portrait-page tabbable"
  80.           oncommand="parentNode.parentNode.orient('portrait');"/>
  81.         <xul:toolbarbutton label="&landscape.label;" 
  82.           accesskey="&landscape.accesskey;"
  83.           type="radio" group="orient" class="toolbar-landscape-page tabbable"
  84.           oncommand="parentNode.parentNode.orient('landscape');"/>
  85.       </xul:hbox>
  86.  
  87.       <xul:toolbarseparator class="toolbarseparator-primary"/>
  88.       <xul:button label="&close.label;" accesskey="&close.accesskey;"
  89.         oncommand="PrintUtils.exitPrintPreview();" icon="close"/>
  90.       <xul:data value="&customPrompt.title;"/>
  91.     </content>
  92.  
  93.     <implementation>
  94.       <field name="mPrintButton">
  95.         document.getAnonymousNodes(this)[0]
  96.       </field>
  97.       <field name="mPageTextBox">
  98.         document.getAnonymousNodes(this)[5].childNodes[0]
  99.       </field>
  100.       <field name="mTotalPages">
  101.         document.getAnonymousNodes(this)[5].childNodes[2]
  102.       </field>
  103.       <field name="mScaleLabel">
  104.         document.getAnonymousNodes(this)[9].firstChild
  105.       </field>
  106.       <field name="mScaleCombobox">
  107.         document.getAnonymousNodes(this)[10].firstChild
  108.       </field>
  109.       <field name="mOrientButtonsBox">
  110.         document.getAnonymousNodes(this)[12]
  111.       </field>
  112.       <field name="mPortaitButton">
  113.         this.mOrientButtonsBox.childNodes[0]
  114.       </field>
  115.       <field name="mLandscapeButton">
  116.         this.mOrientButtonsBox.childNodes[1]
  117.       </field>
  118.       <field name="mCustomTitle">
  119.         document.getAnonymousNodes(this)[15].firstChild
  120.       </field>
  121.       <field name="mPrintPreviewObs">
  122.       </field>
  123.       <field name="mWebProgress">
  124.       </field>
  125.      
  126.       <constructor>
  127.       <![CDATA[
  128.         var print = PrintUtils.getWebBrowserPrint();
  129.         this.mTotalPages.value = print.printPreviewNumPages;
  130.  
  131.         this.updateToolbar();
  132.  
  133.         // Hide the ``Print...'' button when the underlying gfx code does not
  134.         // support multiple devicecontext to be used concurrently
  135.         // (e.g. printing and printpreview at the same time; required as 
  136.         // legacy support for unices.'s PostScript module (Xprint
  137.         // on unices.does not have problems with that))
  138.         // XXX the scaling widgets, and the orientation widgets on unices.
  139.         var canPrint = true;
  140.         try
  141.         {
  142.           var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  143.           canPrint = prefs.getBoolPref("print.whileInPrintPreview");
  144.           if (!canPrint)
  145.           {           
  146.             // Ask the printerfeatures database if this printer device 
  147.             // supports multiple device instances which can be used
  148.             // concurrently
  149.             var smdci = prefs.getBoolPref("print.tmp.printerfeatures." + 
  150.                                           print.currentPrintSettings.printerName +
  151.                                           ".can_use_multiple_devicecontexts_concurrently");
  152.  
  153.             // We can print from print preview when we can use multiple
  154.             // devicecontext instances in parallel (regardless what
  155.             // "print.whileInPrintPreview" may say here...)
  156.             if (smdci)
  157.             {
  158.               canPrint = true;
  159.             }
  160.           }
  161.  
  162.         } catch(e) {}
  163.  
  164.         if (!canPrint)
  165.         {
  166.           // hide print button
  167.           this.mPrintButton.setAttribute("hidden", "true");
  168.  
  169.           // hide page setup button
  170.           document.getAnonymousNodes(this)[1].setAttribute("hidden", "true");
  171.  
  172.           // hide scale widgets (indices: 8, 9, 10, 11)
  173.           // hide orient widgets (indices: 12, 13)
  174.           for (var i = 8; i <= 13; ++i)
  175.           {
  176.             document.getAnonymousNodes(this)[i].setAttribute("hidden", "true");
  177.           }
  178.         }
  179.       ]]>
  180.       </constructor>
  181.  
  182.       <method name="doPageSetup">
  183.         <body>
  184.         <![CDATA[
  185.           var didOK = PrintUtils.showPageSetup();
  186.           if (didOK) {
  187.             // the changes that effect the UI
  188.             this.updateToolbar();
  189.  
  190.             // Now do PrintPreview
  191.             PrintUtils.printPreview();
  192.           }
  193.         ]]>
  194.         </body>
  195.       </method>
  196.  
  197.       <method name="navigate">
  198.         <parameter name="aDirection"/>
  199.         <parameter name="aPageNum"/>
  200.         <parameter name="aHomeOrEnd"/>
  201.         <body>
  202.         <![CDATA[          
  203.           var print = PrintUtils.getWebBrowserPrint();
  204.           var validInput = false;
  205.           var total;
  206.  
  207.           // we use only one of aHomeOrEnd, aDirection, or aPageNum
  208.           if (aHomeOrEnd)
  209.           {
  210.             var homeOrEnd;
  211.             if (aHomeOrEnd == "home")
  212.             {
  213.               homeOrEnd = print.PRINTPREVIEW_HOME;
  214.               this.mPageTextBox.value = 1;  
  215.             }
  216.             else
  217.             {
  218.               homeOrEnd = print.PRINTPREVIEW_END;
  219.               this.mPageTextBox.value = print.printPreviewNumPages;
  220.             }
  221.             
  222.             print.printPreviewNavigate(homeOrEnd, 0);
  223.             validInput = true;
  224.           }
  225.           else if (aDirection)
  226.           {
  227.             var textBoxStr  = this.mPageTextBox.value;
  228.             var newPageNum  = parseInt(textBoxStr) + aDirection;
  229.             total = print.printPreviewNumPages;
  230.  
  231.             // bounds check potentially user-entered number
  232.             if (newPageNum > 0 && newPageNum <= total) 
  233.             {
  234.               this.mPageTextBox.value = newPageNum;
  235.               print.printPreviewNavigate(
  236.                 print.PRINTPREVIEW_GOTO_PAGENUM, newPageNum);
  237.               validInput = true;
  238.             }
  239.           }
  240.           else 
  241.           {
  242.             total = print.printPreviewNumPages;
  243.  
  244.             // bounds check potentially user-entered number
  245.             if (aPageNum > 0 && aPageNum <= total) 
  246.             {
  247.               print.printPreviewNavigate(
  248.                 print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum);
  249.               validInput = true;
  250.             }
  251.           }
  252.  
  253.           if (validInput)          
  254.           {
  255.             // store the valid page number for future use to replace 
  256.             // the textbox value if erroneous input made it in
  257.             this.mPageTextBox.setAttribute(
  258.               "lastvalid", this.mPageTextBox.value);
  259.           }
  260.           else
  261.           { 
  262.             // restore last known valid value in place of erroneous input
  263.             this.mPageTextBox.value = 
  264.               this.mPageTextBox.getAttribute("lastvalid");
  265.           }
  266.         ]]>
  267.         </body>
  268.       </method>
  269.  
  270.       <method name="promptForScaleValue">
  271.         <parameter name="aValue"/>
  272.         <body>
  273.         <![CDATA[
  274.           var value = Math.round(aValue);
  275.           var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  276.           var promptStr = this.mScaleLabel.value;
  277.           var renameTitle = this.mCustomTitle;
  278.           var result = {value:value};
  279.           var confirmed = promptService.prompt(window, renameTitle, promptStr, result, null, {value:value});
  280.           if (!confirmed || (!result.value) || (result.value == "") || result.value == value) {
  281.             return(-1);
  282.           }
  283.           return result.value;
  284.         ]]>
  285.         </body>
  286.       </method>
  287.  
  288.       <method name="setScaleCombobox">
  289.         <parameter name="aValue"/>
  290.         <body>
  291.         <![CDATA[
  292.           var scaleValues = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2];
  293.  
  294.           aValue = new Number(aValue);
  295.  
  296.           var inx = -1;
  297.           for (var i=0;i<scaleValues.length;i++) {
  298.             if (aValue == scaleValues[i]) {
  299.               this.mScaleCombobox.selectedIndex = i;
  300.               return;
  301.             }
  302.           }
  303.           this.mScaleCombobox.value = "Custom";
  304.         ]]>
  305.         </body>
  306.       </method>
  307.  
  308.       <method name="scale">
  309.         <parameter name="aValue"/>
  310.         <body>
  311.         <![CDATA[
  312.           var print = PrintUtils.getWebBrowserPrint();
  313.           var settings = PrintUtils.getPrintSettings();
  314.           if (aValue == "ShrinkToFit") {
  315.             if (!settings.shrinkToFit) {
  316.               settings.shrinkToFit = true;
  317.               this.savePrintSettings(settings, settings.kInitSaveShrinkToFit | settings.kInitSaveScaling);
  318.               PrintUtils.printPreview();
  319.             }
  320.             return;
  321.           }
  322.  
  323.           if (aValue == "Custom") {
  324.             aValue = this.promptForScaleValue(settings.scaling * 100.0);
  325.             if (aValue >= 10) {
  326.               aValue /= 100.0;
  327.             } else {
  328.               this.mScaleCombobox.selectedIndex = this.mScaleCombobox.getAttribute('lastValidInx');
  329.               return;
  330.             }
  331.           }
  332.  
  333.           this.setScaleCombobox(aValue);
  334.           this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);
  335.  
  336.           settings.shrinkToFit = false;
  337.           settings.scaling = aValue;
  338.           this.savePrintSettings(settings, settings.kInitSaveShrinkToFit | settings.kInitSaveScaling);
  339.           PrintUtils.printPreview();
  340.         ]]>
  341.         </body>
  342.       </method>
  343.  
  344.       <method name="orient">
  345.         <parameter name="aOrientation"/>
  346.         <body>
  347.         <![CDATA[
  348.           var orientValue;
  349.           const kIPrintSettings = Components.interfaces.nsIPrintSettings;
  350.           if (aOrientation == "portrait")
  351.           {
  352.             this.mPortaitButton.checked = true;
  353.             this.mLandscapeButton.checked = false;
  354.             orientValue = kIPrintSettings.kPortraitOrientation;
  355.           } 
  356.           else
  357.           {
  358.             this.mPortaitButton.checked = false;
  359.             this.mLandscapeButton.checked = true;
  360.             orientValue = kIPrintSettings.kLandscapeOrientation;
  361.           }
  362.  
  363.           var print = PrintUtils.getWebBrowserPrint();
  364.           var settings = PrintUtils.getPrintSettings();
  365.           settings.orientation = orientValue;
  366.           this.savePrintSettings(settings, settings.kInitSaveOrientation);
  367.           PrintUtils.printPreview();
  368.         ]]>
  369.         </body>
  370.       </method>
  371.  
  372.       <method name="updateToolbar">
  373.         <body>
  374.         <![CDATA[
  375.           var print = PrintUtils.getWebBrowserPrint();
  376.           var settings = PrintUtils.getPrintSettings();
  377.  
  378.           var isPortrait = settings.orientation == Components.interfaces.nsIPrintSettings.kPortraitOrientation;
  379.  
  380.           this.mPortaitButton.checked = isPortrait;
  381.           this.mLandscapeButton.checked = !isPortrait;
  382.  
  383.           if (settings.shrinkToFit) {
  384.             this.mScaleCombobox.value = "ShrinkToFit";
  385.           } else {
  386.             this.setScaleCombobox(settings.scaling);
  387.           }
  388.         ]]>
  389.         </body>
  390.       </method>
  391.  
  392.       <method name="savePrintSettings">
  393.         <parameter name="settings"/>
  394.         <parameter name="flags"/>
  395.         <body><![CDATA[
  396.           var PSSVC = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
  397.                                 .getService(Components.interfaces.nsIPrintSettingsService);
  398.           PSSVC.savePrintSettingsToPrefs(settings, true, flags);
  399.         ]]></body>
  400.       </method>
  401.     </implementation>
  402.   </binding>
  403.  
  404. </bindings>
  405.